import swal from 'sweetalert2';
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { ModalDirective } from 'ngx-bootstrap';


import { User } from '../../../core/auth/user.service';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})

export class HomeComponent implements AfterViewInit {
  @ViewChild('agreementModal') public nodeModal: ModalDirective;
  constructor(private router: Router, private route: ActivatedRoute, public user: User) {
  }
  ngAfterViewInit(): void {
    if (this.user.firstLogin && this.nodeModal) {
      this.nodeModal.show();
    }
  }
  public dealWithFirstLogin(): void {
    swal({
      title: '提示!',
      text: '您是第一次登录系统，请重置密码!',
      type: 'info',
      confirmButtonColor: '#3085d6',
      confirmButtonText: '确定!',
      confirmButtonClass: 'btn btn-success',
    }).then((e: any) => {
      this.router.navigate(['/authority/changepassword', {
        'backURL': '/'
      }], { relativeTo: this.route.parent, skipLocationChange: true });
    }, (dismiss: any) => {
      this.router.navigate(['/authority/changepassword', {
        'backURL': '/'
      }], { relativeTo: this.route.parent, skipLocationChange: true });
    });
  }
}
